<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="layout" content="bolao" />
    <g:set var="entityName" value="${message(code: 'user.label', default: 'User')}" />
    <title><g:message code="default.edit.label" args="[entityName]" /></title>
  </head>
  <body>
    <div class="body">
      <g:if test="${flash.message}">
        <div class="message">${flash.message}</div>
      </g:if>
      <g:hasErrors bean="${user}">
        <div class="errors">
          <g:renderErrors bean="${user}" as="list" />
        </div>
      </g:hasErrors>
      <g:form>
        <div class="dialog">
          <fieldset>
            <legend><g:message code="default.edit.label" args="[entityName]" /></legend>
            <input type="hidden" name="id" value="${user.id}" />
            <input type="hidden" name="version" value="${user.version}" />
            <table>
              <tbody>
                <tr class="prop">
                  <td valign="top" class="name"><label for="username"><g:message code="user.username.label" default="Username"/>:</label></td>
                  <td valign="top" class="value ${hasErrors(bean:user,field:'username','errors')}">
                    <input type="text" id="username" name="username" value="${user.username?.encodeAsHTML()}" disabled/>
                  </td>
                </tr>
                <tr class="prop">
                  <td valign="top" class="name"><label for="firstname"><g:message code="user.firstname.label" default="Firstname"/>:</label></td>
                  <td valign="top" class="value ${hasErrors(bean:user,field:'firstname','errors')}">
                    <input type="text" id="firstname" name="firstname" value="${user.firstname?.encodeAsHTML()}"/>
                  </td>
                </tr>
                <tr class="prop">
                  <td valign="top" class="name"><label for="surname"><g:message code="user.surname.label" default="Surname"/>:</label></td>
                  <td valign="top" class="value ${hasErrors(bean:user,field:'surname','errors')}">
                    <input type="text" id="surname" name="surname" value="${user.surname?.encodeAsHTML()}"/>
                  </td>
                </tr>
                <tr class="prop">
                  <td valign="top" class="name"><label for="password"><g:message code="user.password.label" default="Password"/>:</label></td>
                  <td valign="top" class="value ${hasErrors(bean:user,field:'password','errors')}">
                    <input type="password" id="password" name="password" value="${user.password?.encodeAsHTML()}"/>
                    <%--<g:passwordField name="password" value="${user.password?.encodeAsHTML()}" />--%>
                  </td>
                </tr>
                <tr class="prop">
                  <td valign="top" class="name"><label for="active"><g:message code="user.active.label" default="Active"/>:</label></td>
                  <td valign="top" class="value ${hasErrors(bean:user,field:'active','errors')}">
              <g:checkBox name="active" value="${user?.active}"/>
              </td>
              </tr>
              <tr class="prop">
                <td valign="top" class="name"><label for="contactNumber"><g:message code="user.contactNumber.label" default="Contact Number"/>:</label></td>
                <td valign="top" class="value ${hasErrors(bean:user,field:'contactNumber','errors')}">
                  <input type="text" id="contactNumber" name="contactNumber" value="${user.contactNumber?.encodeAsHTML()}"/>
                </td>
              </tr>
              <tr class="prop">
                <td valign="top" class="name"><label for="email"><g:message code="user.email.label" default="Email"/>:</label></td>
                <td valign="top" class="value ${hasErrors(bean:user,field:'email','errors')}">
                  <input type="text" id="email" name="email" value="${user.email?.encodeAsHTML()}"/>
                </td>
              </tr>
              <tr>
                <td colspan="2"><g:message code="user.roles.label" default="Roles"/>:</td>
              </tr>
              <g:each var="entry" in="${roleMap}">
              <tr>
                <td valign="top" class="name" align="left">${entry.key.description.encodeAsHTML()}</td>
                <td>
                <g:if test="${entry.key.code == 'ROLE_USER'}">
                  <g:checkBox name="${entry.key.code}" value="${entry.value}" disabled="true"/>
                </g:if>
                <g:else>
                  <g:checkBox name="${entry.key.code}" value="${entry.value}"/>
                </g:else>
                </td>
              </tr>
              </g:each>

<%--
                  <div class="list">
                    <table class="table">
                    <thead>
                      <tr>
                        <th width="10px"></th>
                        <th><g:message code="role.label" /></th>
                      </tr>
                    </thead>
                    <tbody>


                    <g:each var="entry" in="${roleMap}">
                      <g:set var="isDisabled" value="" />
                      <g:set var="isChecked" value="false" />
                      <g:if test="${entry.key.code == 'ROLE_USER'}">
                        <g:set var="isChecked" value="true" />
                        <g:set var="isDisabled" value="true" />
                      </g:if>
                      <tr>
                        <td><g:checkBox name="${entry.key.code}" value="${entry.value}" checked="${isChecked}" disabled="${isDisabled}"/></td>
                        <td>${entry.key.description.encodeAsHTML()}</td>
                      </tr>
                      </g:each>
                    </tbody>
                    </table>
                  </div>
 --%>
                </td>
              </tr>
              </tbody>
            </table>
          </fieldset>
        </div>
        <div class="buttons">
          <span class="button"><g:actionSubmit class="save" value="${message(code:'global.update')}" action="update" /></span>
          <span class="button"><g:actionSubmit class="delete" action="delete" value="${message(code: 'default.button.delete.label', default: 'Delete')}" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Are you sure?')}');" /></span>
        </div>
      </g:form>
    </div>
  </body>
</html>